package edu.hawaii.duedates;

import java.util.Date;

/**
 * The class pairs is parameterized type to handle the dates and book titles to be 
 * entered into the arraylist.
 * 
 * @author Daniel Arakaki, John Ancheta, Mari-lee Flestado
 * @version 1.0, October 25, 2008
 *
 */
public class Pair implements Comparable<Pair> {

  /** A string for the book's date due. */
  private final Date dateDue;
  
  /** A string for the book's title. */
  private final String bookTitle;
  
  /**
   * The constructor initializes two string objects for use.
   * 
   * @param dateConverted The book's due date.
   * @param bookInfoTwo The book's title.
   */
  public Pair(Date dateConverted, String bookInfoTwo) {
    this.dateDue = new Date(dateConverted.getTime());
    this.bookTitle = bookInfoTwo;
  }
  
  /**
   * A getter method to retrieve the book's due date.
   * 
   * @return A Date that is the book's due date.
   */
  public Date getDueDate() {
    return new Date(this.dateDue.getTime());
  }
  
  /**
   * A getter tmethod to retrieve the book's title.
   * 
   * @return A String that is the book's title.
   */
  @Override
  public String toString() {
    return this.bookTitle;
  }
  
  /**
   * A getter method to retrieve the book's title.
   * 
   * @return A string that is the book's title.
   */
  public String getBookTitle() {
    return this.bookTitle;
  }
  
  /**
   * Overriding the equals method checking if the Date values are equal and String values are equal.
   * 
   * @return true If the date values are equal and string values are equal.
   *         false If the date values are not equal and string values are not equal.
   *         
   * @param obj The String bookTitle or the Date dateDue.
   */
  @Override
  public boolean equals(Object obj) {
    
    if (obj instanceof Pair) {
      Pair pair = (Pair) obj;
      return pair.getDueDate().equals(this.dateDue) && pair.getBookTitle().equals(this.bookTitle);
    }
    return false;
  }
  
  /**
   * Overriding default hashCode. 
   * 
   * @return int Returning unique Pair hashCode.
   */
  @Override
  public int hashCode() {
    return this.dateDue.hashCode() + this.bookTitle.hashCode();
  }

  /**
   * The compare method does a comparison of dates so it sorts the dates in ascending order.
   * 
   * @param aPair The argument is a parameterized type.
   * @return results An integer that flags the sort method.
   */
  public int compareTo(Pair aPair) {
    Date date = aPair.getDueDate(); 
    //aPair = new Pair(dateDue, bookTitle);
    return this.dateDue.compareTo(date);
  }
}
